#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define MAXSIZE 100
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR -1
#define OVERFLOW -2
typedef int ElemType;
typedef int Status;
typedef struct {
    ElemType* elem;
    int front;
    int rear;
    int length;
}SqQueue;
Status InitQueue(SqQueue &SQ) {
    SQ.elem = (ElemType*)malloc(sizeof(ElemType) * MAXSIZE);
    if (!SQ.elem)
        exit(OVERFLOW);
    SQ.front = SQ.rear = 0;
    SQ.length = 0;
    return OK;
}
Status EnQueue(SqQueue &SQ, ElemType e) {
    if ((SQ.rear + 1) % MAXSIZE == SQ.front)
        return ERROR;
    SQ.elem[SQ.rear] = e;
    SQ.rear = (SQ.rear + 1) % MAXSIZE;
    ++SQ.length;
    return OK;
}
Status DeQueue(SqQueue &SQ, ElemType &e) {
    if (SQ.front == SQ.rear) {
        return ERROR;
    }
    e = SQ.elem[SQ.front];
    SQ.front = (SQ.front + 1) % MAXSIZE;
    --SQ.length;
    return OK;
}
void showQueue(SqQueue SQ) {
    printf("队头->队尾\n");
    for (int i = 0; i < SQ.length; ++i) {
        printf("%d ", SQ.elem[(SQ.front + i) % MAXSIZE]);
    }
    printf("\n");
}
int main(void) {
    SqQueue sq;
    InitQueue(sq);
    ElemType e = 2;
    EnQueue(sq, e);
    e = 9;
    EnQueue(sq, e);
    showQueue(sq);
    DeQueue(sq, e);
    printf("e = %d\n", e);
    showQueue(sq);

    return 0;
}